package com.mindskip.xzs.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.domain.Subject;
import com.mindskip.xzs.domain.Video;
import com.mindskip.xzs.repository.BaseMapper;
import com.mindskip.xzs.repository.SubjectMapper;
import com.mindskip.xzs.repository.VideoMapper;
import com.mindskip.xzs.service.VideoService;
import com.mindskip.xzs.viewmodel.admin.education.VideoPageRequestVM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author changjiang
 * @Title:
 * @Package
 * @Description: 视频
 * @date 2022/1/209:27 下午
 */

@Service
public class VideoServiceImpl extends BaseServiceImpl<Video> implements VideoService {

    private final VideoMapper videoMapper;

    public VideoServiceImpl(BaseMapper<Video> baseMapper, VideoMapper videoMapper) {
        super(baseMapper);
        this.videoMapper = videoMapper;
    }


    @Override
    @Cacheable(value = "video_select1", key = "#id", unless = "#result == null")
    public Video selectById(Integer id) {
        return super.selectById(id);
    }


    @Override
    public List<Video> getVideo(Video video) {
        return videoMapper.selectByVideo(video);
    }

    @Override
    public List<Video> videoPage(VideoPageRequestVM requestVM) {
        return videoMapper.videoPage(requestVM);
    }

    @Override
    public PageInfo<Video> page(VideoPageRequestVM requestVM) {
        String orderBy = "sort";
        if(null == requestVM.getSort()){
            requestVM.setSort(0);
        }
        if(requestVM.getSort()==1) {
            orderBy = "sort desc";
        }
        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), orderBy).doSelectPageInfo(() ->
                videoMapper.videoPage(requestVM)
        );
    }

    @Override
    public PageInfo<Video> pageList(VideoPageRequestVM requestVM) {
        String orderBy = "update_time desc";
        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), orderBy).doSelectPageInfo(() ->
                videoMapper.videoPage(requestVM)
        );
    }

    @Override
    public PageInfo<Video> page2(VideoPageRequestVM requestVM) {
        String orderBy = "sort";
        if(null == requestVM.getSort()){
            requestVM.setSort(0);
        }
        if(requestVM.getSort()==1){
            orderBy = "sort desc";
        }
        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), orderBy).doSelectPageInfo(() ->
                videoMapper.videoPage2(requestVM)
        );
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return videoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertSelective(Video record) {
        return videoMapper.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(Video record) {
        return videoMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Video record) {
        return videoMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Video> getVideoPaper(Video video) {
        return videoMapper.getVideoPaper(video);
    }

    @Override
    public Video getVideoByTag(Video video) {
        return videoMapper.getVideoByTag(video);
    }

    @Override
    public List<Video> videoPage2List(Video video) {
        return videoMapper.videoPage2List(video);
    }


}
